#include<stdio.h>
int power(int b, int count)
{
	int sum = 1;
	for (int i = 0; i < count; ++i)
	{
		sum *= b;
	}
	return sum;
}
int main()
{
	int a;
	scanf_s("%d", &a);
	int b;
	int count;
	for (int i = 0; i < a; ++i)
	{
		b = i;
		int c = i;
		int sum = 0;
		count = 0;
		while (c)
		{
			c /= 10;
			count++;
		}
		while (b / 10)
		{
			sum = sum + power(b % 10, count);
			b /= 10;
		}
		sum = sum + power(b % 10, count);
		if (sum == i || i == 0)
		{
			printf("%d ", i);
		}
	}
	return 0;
}